## Untitled - By: STM32 - 周四 四月 19 2018
import sensor,image,time,lcd
from pyb import UART,Timer,LED

lcd.init()
#uart = UART(3,115200,8,None,1)

#二维码识别，并返回识别结果
def Color_Check(uart):
    sensor.set_framesize(sensor.VGA)
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_contrast(0)
    sensor.set_brightness(0)
    sensor.set_saturation(0)
    #sensor.set_contrast(-3)
    sensor.set_windowing((150,150,480,240))
    img = sensor.snapshot()
    for code in img.find_qrcodes():
        print(code)
        qr_Tab = code.payload()
        img.draw_string(code.x() - 10, code.y()-20, qr_Tab, color = (255,0,0),scale = 2, mono_space = False)
        uart.writechar(0x55)
        uart.writechar(0x02)
        uart.writechar(0x92)
        uart.writechar(0x01)#  识别成功
        uart.writechar(len(qr_Tab))
        for qrdata in qr_Tab:
            uart.writechar(ord(qrdata))
        uart.writechar(0xBB)
        lcd.display(img)
        return 1
    lcd.display(img)
    return 0



